/*
 * @Author: biluo
 * @Date: 2021-04-08 15:49:18
 * @LastEditTime: 2021-04-08 21:22:41
 * @FilePath: \codee:\webNew\test\directive_vue\src\utils\utilJS\validatorFrom\validator.js
 */
import validatorFunc from './validatorUtil/index.js';
// const validatorFunc = require('./validatorUtil/index.js')
console.log(validatorFunc)
class Validator {
	constructor(form, rules) {
		this.rules = rules
		this.form = form
		this.validateResult = []
		this.addRules()
	}
	addRules() {
		for (let [key, value] of Object.entries(this.form)) {
			const rule = this.rules[key]
			// console.log(rule);
			rule.forEach(item => {
				for (let [ke, val] of Object.entries(item)) {
					// console.log(ke,validatorFunc.hasOwnProperty(ke))
					if (validatorFunc.hasOwnProperty(ke)) {
						let res = [value, val, item.message]
						
						// console.log(ke, res, validatorFunc[ke],validatorFunc[ke].apply(this, res))
						this.validateResult.push(function() {
							return validatorFunc[ke].apply(this, res)
						})
					}
				}
			})
		}
	}
	validate() {
		console.log(this.validateResult)
		for (let i = 0, validatorFun; validatorFun = this.validateResult[i++];) {
            var msg = validatorFun()
			// console.log(msg)
            if (msg) {
                return msg
            }
        }
	}

}

export default Validator
